package com.nage.components.touch.menu;

import android.util.Log;

import com.nage.R;
import com.nage.components.touch.Touchable;
import com.nage.engine.GameGraphBuilder;
import com.nage.engine.GameObject;
import com.nage.engine.Main;
import com.nage.input.InputSystem;

public class JoinMultiplayerGame extends Touchable {

	public JoinMultiplayerGame(GameObject p) {
		super(p);
		type = JOIN_MULTIPLAYER;
	}

	@Override
	public void onTouch() {
		Main.engine.endCurrentSimulation();
		InputSystem.clearResponders();
		Main.engine.initSimulationSystem(GameGraphBuilder.load(Main.engine.context.getResources().getXml(R.xml.multiplayergame), Main.engine.context));
		Main.engine.ms.serverMode = false;
		try {
			Main.engine.linkSystems();
		} catch (Exception e) {
			Log.e("JoinMultiplayerGame", "Cannot join new multiplayer game: "+e.getMessage());
		}		
	}

}
